import { Resolver,Query, Args, Mutation } from '@nestjs/graphql';
import { MutationRes } from 'src/modules/shared/vo/mutation.res';
import { ModifyAccountInput } from '../../dto/modifyAccount.input';
import { AccountEntity } from '../../entities/account.entity';
import { AccountService } from '../../services/account/account.service';

@Resolver()
export class AccountResolver {
    constructor(private readonly accountService: AccountService){

    }

    @Query(() => [AccountEntity!]!, {description: '账户列表'})
    async accountList(){
        return await this.accountService.accountList();
    }

    @Query(() => AccountEntity!, { description: '根据账号id查询账号信息' })
    async account(
        @Args('id') id: number,
    ){
      return await this.accountService.account(id);
    }
 

    @Mutation(() => MutationRes, {name: 'createAccount', description: '创建账户'})
    async createAccount(
        @Args('username') username: string,
        @Args('password') password: string
    ): Promise<MutationRes>{
       return await this.accountService.createAccount(username, password)
    }

    @Mutation(() => MutationRes, {nullable: false, name: 'modifyAccountById', description: '根据id修改数据' })
    async modifyAccountById(
        @Args('id') id: number,
        @Args('data') modifyAccountInput: ModifyAccountInput
    ): Promise<MutationRes>{
       return await this.accountService.modifyAccountById(id, modifyAccountInput)
    }

    @Mutation(() => MutationRes, {nullable: false, name: 'deleteAccountById', description: '根据id删除账户' })
    async deleteAccountById(
        @Args('id') id: number
    ): Promise<MutationRes>{
       return await this.accountService.deleteAccountById(id)
    }

}
